home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue69 / Alfresco / TstCF.dpr < prev   
Encoding:
Text File  |  2001-04-04  |  3.3 KB  |  135 lines

  1. program TstCF;
  2.  
  3. {$apptype console}
  4.  
  5. uses
  6.   SysUtils,
  7.   Classes,
  8.   AACpndF;
  9.  
  10. procedure PrintFolder(var aDirEntry : TaaCFDirEntry;
  11.                       var aStopWalk : boolean);
  12. begin
  13.   if (aDirEntry.deType = detFolder) then
  14.     writeln('folder: ', aDirEntry.deName)
  15.   else
  16.     writeln('file:   ', aDirEntry.deName);
  17. end;
  18.  
  19.  
  20. var
  21.   CF : TaaCompoundFile;
  22.   SF : TaaSubfileStream;
  23.   FS : TFileStream;
  24.   Test1Folder : TaaHandle;
  25.   Test2Folder : TaaHandle;
  26. begin
  27.   writeln('create a new compound file');
  28.   CF := nil;
  29.   try
  30.     CF := TaaCompoundFile.Create('c:\CF.DAT', fmCreate);
  31.   finally
  32.     CF.Free;
  33.   end;
  34.  
  35.   writeln('open an existing empty compound file');
  36.   CF := nil;
  37.   try
  38.     CF := TaaCompoundFile.Create('c:\CF.DAT', fmOpenReadWrite);
  39.     writeln('add /test1 folder');
  40.     Test1Folder := CF.AddFolder(CF.Root, 'test1');
  41.     writeln('add /test1/test2 folder');
  42.     Test2Folder := CF.AddFolder(Test1Folder, 'test2');
  43.     writeln('dir listing of /test1');
  44.     CF.WalkFolder(Test1Folder, PrintFolder);
  45.     writeln('..end');
  46.     writeln('dir listing of /test1/test2');
  47.     CF.WalkFolder(Test2Folder, PrintFolder);
  48.     writeln('..end');
  49.     CF.CloseFolder(Test1Folder);
  50.     CF.CloseFolder(Test2Folder);
  51.   finally
  52.     CF.Free;
  53.   end;
  54.  
  55.   writeln('open an existing compound file');
  56.   CF := nil;
  57.   try
  58.     CF := TaaCompoundFile.Create('c:\CF.DAT', fmOpenReadWrite);
  59.     writeln('open /test1 folder');
  60.     Test1Folder := CF.OpenFolder(CF.Root, 'test1');
  61.     writeln('open /test1/test2 folder');
  62.     Test2Folder := CF.OpenFolder(Test1Folder, 'test2');
  63.     writeln('dir listing of /test1');
  64.     CF.WalkFolder(Test1Folder, PrintFolder);
  65.     writeln('..end');
  66.     writeln('dir listing of /test2');
  67.     CF.WalkFolder(Test2Folder, PrintFolder);
  68.     writeln('..end');
  69.  
  70.     writeln('create new subfile');
  71.     SF := TaaSubfileStream.Create(CF, Test2Folder, 'SomeFile', true);
  72.     try
  73.  
  74.       writeln('write to subfile');
  75.       FS := TFileStream.Create('AAIntLst.pas', fmOpenRead);
  76.       try
  77.         SF.CopyFrom(FS, FS.Size);
  78.       finally
  79.         FS.Free;
  80.       end;
  81.  
  82.     finally
  83.       writeln('free subfile');
  84.       SF.Free;
  85.     end;
  86.  
  87.     CF.CloseFolder(Test1Folder);
  88.     CF.CloseFolder(Test2Folder);
  89.   finally
  90.     CF.Free;
  91.   end;
  92.  
  93.   writeln('open an existing compound file with subfile');
  94.   CF := nil;
  95.   try
  96.     CF := TaaCompoundFile.Create('c:\CF.DAT', fmOpenReadWrite);
  97.     writeln('open /test1 folder');
  98.     Test1Folder := CF.OpenFolder(CF.Root, 'test1');
  99.     writeln('open /test1/test2 folder');
  100.     Test2Folder := CF.OpenFolder(Test1Folder, 'test2');
  101.     writeln('dir listing of /test1');
  102.     CF.WalkFolder(Test1Folder, PrintFolder);
  103.     writeln('..end');
  104.     writeln('dir listing of /test2');
  105.     CF.WalkFolder(Test2Folder, PrintFolder);
  106.     writeln('..end');
  107.  
  108.     writeln('open existing subfile');
  109.     SF := TaaSubfileStream.Create(CF, Test2Folder, 'SomeFile', false);
  110.     try
  111.  
  112.       writeln('read from subfile');
  113.       FS := TFileStream.Create('c:\test.pas', fmCreate);
  114.       try
  115.         SF.Seek(0, soFromBeginning);
  116.         FS.CopyFrom(SF, SF.Size);
  117.       finally
  118.         FS.Free;
  119.       end;
  120.  
  121.     finally
  122.       writeln('free subfile');
  123.       SF.Free;
  124.     end;
  125.  
  126.     CF.CloseFolder(Test1Folder);
  127.     CF.CloseFolder(Test2Folder);
  128.   finally
  129.     CF.Free;
  130.   end;
  131.  
  132.  
  133.   readln;
  134. end.
  135.